package com.koron.css2.workflow.service;

import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.DateUtils;
import org.koron.ebs.mybatis.SessionFactory;

import java.time.LocalTime;
import java.util.Date;

public class PjProcessNodeTimePostponeService {

    // 假设工作时间为9:00 AM 至 5:00 PM
    private static final LocalTime WORK_AM_START = LocalTime.of(9, 0);
    private static final LocalTime WORK_AM_END = LocalTime.of(12, 0);
    private static final LocalTime WORK_PM_START = LocalTime.of(14, 0);
    private static final LocalTime WORK_PM_END = LocalTime.of(18, 0);

    public void syncProcessHistory(SessionFactory factory, String setCode, String processCode, String billId, UserInfoBean userInfo){
        /*PjInfoMapper pjInfoMapper = factory.getMapper(PjInfoMapper.class);
        PubReceiptMapper pubReceiptMapper = factory.getMapper(PubReceiptMapper.class, DBSourceUtils.getDbEnv(userInfo.getCurWaterCode()));
        List<HistoryTaskMsgBean> historyTaskMsgList = WorkflowImpl.workflowhistory(setCode, processCode, billId);
        if (historyTaskMsgList.size() > 0){
            HistoryTaskMsgBean historyTaskMsg = historyTaskMsgList.get(historyTaskMsgList.size() - 1);
            PjProcessNodeTimePostponeBean postpone = new PjProcessNodeTimePostponeBean();
            postpone.setId(Tools.getObjectId());
            postpone.setBillId(billId);
            postpone.setStartTime(DateUtils.parseDate(historyTaskMsg.getStartTime()));
            postpone.setComplateTime(DateUtils.parseDate(historyTaskMsg.getOperationTime()));
            postpone.setTaskName(historyTaskMsg.getNowNodeName());
            postpone.setOperation(historyTaskMsg.getOperation());
            postpone.setComments(historyTaskMsg.getComment());
            postpone.setOperator(historyTaskMsg.getOperationUserName());
            long timeConsum = DateUtils.deltaOfTwoTime(postpone.getStartTime(), postpone.getComplateTime());
            postpone.setTimeConsum(timeConsum);
            PjInfoBean pjInfo = pjInfoMapper.selectById(billId);
            ProcessNodeBean processNode = pubReceiptMapper.selectProcessNodeBean("pj_info#" + pjInfo.getPjType(), historyTaskMsg.getNowNodeCode());
            if (processNode.getTimeOut() != null){
                postpone.setPlanTime(processNode.getTimeOut());
                Date planComplateTime = DateUtils.addHours(postpone.getStartTime(), processNode.getTimeOut());
                postpone.setPlanComplateTime(planComplateTime);
            }
        }*/
    }

    private int calculateWorkingHours(Date startTime, Date endTime, boolean isWhole){
        if (isWhole){
            int days = DateUtils.betweenDays(startTime, endTime);
            for (int i = 0; i < days; i++){

            }
        }
        return 0;
    }

    /**
     * 判断该时间是否处于节假日
     * @param time
     * @return
     */
    private boolean isVacation(Date time){

        return false;
    }

    /**
     * 判断该时间是否处于工作日
     * @param time
     * @return
     */
    private boolean isWeekday(Date time){
        return false;
    }
}
